package com.dao;

import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;

import org.apache.log4j.Logger;
import org.hibernate.Query;

import com.base.BaseDao;
import com.base.UserBean;
import com.bean.Money;
import com.bean.ParkManager;
import com.bean.ParkOrder;
import com.bean.Parkinfo;
import com.bean.StatusOrder;
import com.tool.DateTimeTools;
import com.util.GUtil;

/**
 * A data access object (DAO) providing persistence and search support for
 * ParkOrder entities. Transaction control of the save(), update() and delete()
 * operations can directly support Spring container-managed transactions or they
 * can be augmented to handle user-managed Spring transactions. Each of these
 * methods provides additional information for how to configure it for the
 * desired type of transaction control.
 * 
 * @see com.bean.ParkOrder
 * @author MyEclipse Persistence Tools
 */
public class OrderStatisticsDao extends BaseDao {
	private static final Logger log = Logger.getLogger(OrderStatisticsDao.class);
	// property constants
	public static final String PO_NO = "poNo";
	public static final String PO_TYPE = "poType";
	public static final String CAR_NO = "carNo";
	public static final String CAR_COLOR = "carColor";
	public static final String CAR_BRAND = "carBrand";
	public static final String ENTER_IMG = "enterImg";
	public static final String LEAVE_IMG = "leaveImg";
	public static final String RESERVATION_DURATION = "reservationDuration";
	public static final String ACTUAL_DURATION = "actualDuration";
	public static final String RESERVATION_AMOUNT = "reservationAmount";
	public static final String RECEIVABLE_AMOUNT = "receivableAmount";
	public static final String ACTUAL_AMOUNT = "actualAmount";
	public static final String DIFF_AMOUNT = "diffAmount";
	public static final String PARK_PRICE = "parkPrice";
	public static final String CHANGE_AMOUNT_REASON = "changeAmountReason";
	public static final String CARPORT_COUNT = "carportCount";
	public static final String COMMENT_STATUS = "commentStatus";
	public static final String REPORT_STATUS = "reportStatus";
	public static final String STATUS = "status";


	// 停车场管理员查询本停车场的所有订单
	public List<ParkOrder> queryMyParkOrder(ParkOrder object, UserBean userBean) {
		session = getSession();
		log.debug("finding all ParkOrder instances");
		StringBuffer sb = new StringBuffer();
		try {
			sb.append("from ParkOrder where parkinfo.PId in( select PId from ParkinfoManagerRelevance where userId=?) and "
					+ " ((poType=1 and status in(1,2,3)) or (poType=2 and status =2)) ");
			ParkManager pm = (ParkManager) session.get(ParkManager.class,
					userBean.getId());
			if (pm == null)
				return null;

			if (object != null && !"".equals(object)) {
				// 订单类型
				if (object.getStatus() != null
						&& !"".equals(object.getStatus())) {
					Short s = object.getStatus();
					sb.append(" and status ='" + s + "'");
				}
				// 车场
				if (object.getParkinfo() != null) {
					Integer Pid = object.getParkinfo().getPId();
					if (object.getParkinfo().getPId() != null
							&& !"".equals(object.getParkinfo().getPId())) {
						sb.append(" and parkinfo.PId='" + Pid + "'");
					}
				}
				// 订单时间
				if (object.getOrderTime() != null
						&& !"".equals(object.getOrderTime())) {
					Timestamp t = object.getOrderTime();
					sb.append(" and orderTime like '" + t + "%'");
				}
				// 订单号
				if (object.getPoNo() != null && !"".equals(object.getPoNo())) {
					sb.append(" and poNo like '%" + object.getPoNo() + "%'");
				}
				// 车牌号
				if (object.getCarNo() != null && !"".equals(object.getCarNo())) {
					sb.append(" and carNo like '%" + object.getCarNo() + "%'");
				}
				// 用户名
				if (object.getUserinfo() != null) {
					if (object.getUserinfo().getRealName() != null
							&& !"".equals(object.getUserinfo().getRealName())) {
						sb.append(" and userinfo.realName like '%"
								+ object.getUserinfo().getRealName() + "%'");
					}
				}
			}
			sb.append(" order by poId asc");

			Query query = session.createQuery(sb.toString());
			query.setLong(0, pm.getUserId());
			return query.list();
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}

	// 订单管理的query，-3：超时未支付的订单；-2：超时未确认定的订单；-1：管理员确认无法预订；0：订单已取消
	public List<ParkOrder> queryParkOrder(ParkOrder object, UserBean userBean) {
		session = getSession();
		log.debug("finding all ParkOrder instances");
		StringBuffer sb = new StringBuffer();
		try {
			session = this.getSession();
			ParkManager pm = (ParkManager) session.get(ParkManager.class,
					userBean.getId());
			if (pm == null)
				return null;
			sb.append("from ParkOrder where parkinfo.PId in( select PId from ParkinfoManagerRelevance where userId=?) and"
					+ "  ((status in(1,2,3,0,-1)))");
			if (object != null && !"".equals(object)) {
				// 订单类型
				if (object.getStatus() != null
						&& !"".equals(object.getStatus())) {
					Short s = object.getStatus();
					sb.append(" and status ='" + s + "'");
				}
				// 车场
				if (object.getParkinfo() != null) {
					Integer Pid = object.getParkinfo().getPId();
					if (object.getParkinfo().getPId() != null
							&& !"".equals(object.getParkinfo().getPId())) {
						sb.append(" and parkinfo.PId='" + Pid + "'");
					}
				}
				// 订单时间
				if (object.getOrderTime() != null
						&& !"".equals(object.getOrderTime())) {
					Timestamp t = object.getOrderTime();
					sb.append(" and orderTime like '" + t + "%'");
				}
				// 订单号
				if (object.getPoNo() != null && !"".equals(object.getPoNo())) {
					sb.append(" and poNo like '%" + object.getPoNo() + "%'");
				}
				// 车牌号
				if (object.getCarNo() != null && !"".equals(object.getCarNo())) {
					sb.append(" and carNo like '%" + object.getCarNo() + "%'");
				}
				// 用户名
				if (object.getUserinfo() != null) {
					if (object.getUserinfo().getRealName() != null
							&& !"".equals(object.getUserinfo().getRealName())) {
						sb.append(" and userinfo.realName like '%"
								+ object.getUserinfo().getRealName() + "%'");
					}
				}
			}

			sb.append("order by poId asc");

			Query query = session.createQuery(sb.toString());
			query.setLong(0, pm.getUserId());
			return query.list();
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}

	// 收费员查询自己的订单
	public List<ParkOrder> queryMyOrder(ParkOrder object, UserBean userBean) {
		session = getSession();
		log.debug("finding all ParkOrder instances");
		StringBuffer sb = new StringBuffer();
		try {
			sb.append("from ParkOrder where 1=1");
			if (object != null && !"".equals(object)) {
				// 订单类型
				if (object.getStatus() != null
						&& !"".equals(object.getStatus())) {
					Short s = object.getStatus();
					sb.append(" and status ='" + s + "'");
				}
				// 车场
				if (object.getParkinfo() != null) {
					Integer Pid = object.getParkinfo().getPId();
					if (object.getParkinfo().getPId() != null
							&& !"".equals(object.getParkinfo().getPId())) {
						sb.append(" and parkinfo.PId='" + Pid + "'");
					}
				}
				// 订单时间
				if (object.getOrderTime() != null
						&& !"".equals(object.getOrderTime())) {
					Timestamp t = object.getOrderTime();
					sb.append(" and orderTime like '" + t + "%'");
				}
				// 订单号
				if (object.getPoNo() != null && !"".equals(object.getPoNo())) {
					sb.append(" and poNo like '%" + object.getPoNo() + "%'");
				}
				// 车牌号
				if (object.getCarNo() != null && !"".equals(object.getCarNo())) {
					sb.append(" and carNo like '%" + object.getCarNo() + "%'");
				}
				// 用户名
				if (object.getUserinfo() != null) {
					if (object.getUserinfo().getRealName() != null
							&& !"".equals(object.getUserinfo().getRealName())) {
						sb.append(" and userinfo.realName like '%"
								+ object.getUserinfo().getRealName() + "%'");
					}
				}
			}
			sb.append("order by poId asc");

			Query queryObject = session.createQuery(sb.toString());
			return queryObject.list();
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}

	public List getAll(ParkOrder object) {
		session = getSession();
		log.debug("finding all ParkOrder instances");
		StringBuffer sb = new StringBuffer();
		try {
			sb.append("from ParkOrder where 1=1");
			if (object != null && !"".equals(object)) {
				// 订单类型
				if (object.getStatus() != null
						&& !"".equals(object.getStatus())) {
					Short s = object.getStatus();
					sb.append(" and status ='" + s + "'");
				}
				// 车场
				if (object.getParkinfo() != null) {
					Integer Pid = object.getParkinfo().getPId();
					if (object.getParkinfo().getPId() != null
							&& !"".equals(object.getParkinfo().getPId())) {
						sb.append(" and parkinfo.PId='" + Pid + "'");
					}
				}
				// 订单时间
				if (object.getOrderTime() != null
						&& !"".equals(object.getOrderTime())) {
					Timestamp t = object.getOrderTime();
					sb.append(" and orderTime like '" + t + "%'");
				}
				// 订单号
				if (object.getPoNo() != null && !"".equals(object.getPoNo())) {
					sb.append(" and poNo like '%" + object.getPoNo() + "%'");
				}
				// 车牌号
				if (object.getCarNo() != null && !"".equals(object.getCarNo())) {
					sb.append(" and carNo like '%" + object.getCarNo() + "%'");
				}
				// 用户名
				if (object.getUserinfo() != null) {
					if (object.getUserinfo().getRealName() != null
							&& !"".equals(object.getUserinfo().getRealName())) {
						sb.append(" and userinfo.realName like '%"
								+ object.getUserinfo().getRealName() + "%'");
					}
				}
			}
			sb.append("order by poId asc");

			Query queryObject = session.createQuery(sb.toString());
			return queryObject.list();
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}
	
	/*
	 * 删除
	 */
	public void delete(ParkOrder order) {
		log.debug("deleting ParkOrder instance");
		try {
			getSession().delete(order);
			log.debug("delete successful");
		} catch (RuntimeException re) {
			log.error("delete failed", re);
			throw re;
		}
	}

	public ParkOrder findById(Long id) {
		log.debug("getting ParkOrder instance with id: " + id);
		try {
			ParkOrder instance = (ParkOrder) getSession().get(ParkOrder.class,
					id);
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}


	public String delete(Long id, Integer flag) {
		ParkOrder po = this.findById(id);
		if (po != null) {
			return delete(po, flag);
		} else {
			return GUtil.FAILE;
		}
	}

	public String delete(ParkOrder order, Integer flag) {
		log.debug("deleting ParkOrder instance");
		try {
			if (flag == null)
				getSession().delete(order);
			else {
				order.setStatus(flag.shortValue());
				getSession().update(order);
			}
			log.debug("delete successful");
		} catch (RuntimeException re) {
			log.error("delete failed", re);
			throw re;
		}
		return GUtil.SUCCESS;
	}
	
	public List<Parkinfo> findparkname() {
		log.debug("finding all ParkOrder instances   ");
		try {
			String queryString = " from Parkinfo";
			Query queryObject = getSession().createQuery(queryString);
			return queryObject.list();
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}
	/*
	 * 椭圆数据
	 * select 100*sum(p.status in(3))/sum(p.status in(3,-1,2,1)),100*sum(p.status in(-1))/sum(p.status in(3,-1,2,1))," +
						"100*sum(p.status in (2))/sum(p.status in(3,-1,2,1)),100*sum(p.status in(1))/sum(p.status in(3,-1,2,1)) from ParkOrder p where 1=1
	 */
	public List<ParkOrder> MyOrderstatis(ParkOrder parkOrder) {
		session = getSession();
		log.debug("finding all ParkOrder instances");
		StringBuffer sb = new StringBuffer();
		try {
			sb.append("select 100*sum(status in(3))/sum(status in(3,-1,2,1,-2)),100*sum(status in(-1))/sum(status in(3,-1,2,1,-2)) 100*sum(status in (2))/sum(status in(3,-1,2,1,-2))," +
					"100*sum(status in(1))/sum(status in(3,-1,2,1,-2)),100*sum(status not in(-1,1,2,3))/sum(status  in(3,-1,2,1,-2)),sum(receivable_amount),sum(actual_amount) " +
					"from park_order p");
			if (parkOrder != null && !"".equals(parkOrder)) {
				if (parkOrder.getOrderTime() != null
						&& !"".equals(parkOrder.getOrderTime())) {
					sb.append(" and orderTime like '" + parkOrder.getOrderTime()
							+ "%'");
				}
			}
			List list = session.createSQLQuery(sb.toString()).list();
			   
			//List<ParkOrder> list = queryObject.list();
			return list;
		} catch (RuntimeException e) {
			log.error("find all failed", e);
			throw e;
		}
	}
	/*
	 * 折现数据
	 */
	public List<ParkOrder> Orderstatis(ParkOrder parkOrder) {
		session = getSession();
		log.debug("finding all ParkOrder instances");
		StringBuffer sb = new StringBuffer();
		try {
			sb.append("select sum(status in(3)),sum(status in(-1)),sum(status in (2)),sum(status in(1)),sum(status not in(-1,1,2,3)),count(*) from park_order where 1=1");
			if (parkOrder != null && !"".equals(parkOrder)) {
				if (parkOrder.getOrderTime() != null
						&& !"".equals(parkOrder.getOrderTime())) {
					sb.append(" and order_time like '" + parkOrder.getOrderTime()
							+ "%'");
				}
			}
			List list = session.createSQLQuery(sb.toString()).list();
			return list;
		} catch (RuntimeException e) {
			// TODO: handle exception
			System.out.println("折线订单统计出错："+e.getStackTrace());
			log.error("find all failed", e);
			throw e;
		}
	}
	/*
	 * 绩效统计 "SELECT SUM(actualAmount),p.realName,pi.PName," +
	 * "COUNT(po.parkManagerByLeaveOperatorId.userId),COUNT(po.parkManagerByReservationOperatorId.userId)"
	 * +
	 */
	public List<ParkOrder> statistics(ParkOrder parkOrder) {

		session = getSession();
		log.debug("finding all ParkOrder instances");
		StringBuffer sb = new StringBuffer();
		try {
			sb.append("select po.parkManagerByLeaveOperatorId.realName,po.parkinfo.PName,"
					+ "sum(po.actualAmount),count(po.parkManagerByLeaveOperatorId.userId),count(po.parkManagerByReservationOperatorId.userId),To_Days(MAX(po.orderTime))-To_Days(MIN(po.orderTime))"
					+ "from ParkOrder po,Userinfo u,ParkManager p,Parkinfo pi where 1=1");
			if (parkOrder != null) {
				// 收费员
				if (parkOrder.getParkManagerByLeaveOperatorId() != null) {
					if (parkOrder.getParkManagerByLeaveOperatorId()
							.getRealName() != null
							&& !"".equals(parkOrder
									.getParkManagerByLeaveOperatorId()
									.getRealName())) {
						sb.append(" and po.parkManagerByLeaveOperatorId.realName like '%"
								+ parkOrder.getParkManagerByLeaveOperatorId()
										.getRealName() + "%'");
					}
				}
				// 停车场
				if (parkOrder.getParkinfo() != null) {
					if (parkOrder.getParkinfo().getPId() != null
							&& !"".equals(parkOrder.getParkinfo().getPId())) {
						sb.append(" and po.parkinfo.PId = '"
								+ parkOrder.getParkinfo().getPId() + "'");
					}
				}
				// try {
				// 月份
				// SimpleDateFormat dft = new SimpleDateFormat();
				// String d=parkOrder.getLeaveTime().toString();
				// System.out.println(d+"--------------------------------------------");
				Timestamp t = parkOrder.getLeaveTime();
				if (parkOrder.getLeaveTime() != null
						&& !"".equals(parkOrder.getLeaveTime())) {
					sb.append(" and po.leaveTime like '" + t + "%'");
				}
				// } catch (ParseException e) {
				// e.getStackTrace();
				// }
			}
			sb.append(" and u.userId=po.userinfo.userId and po.parkinfo.PId=pi.PId and "
					+ "p.userId=po.parkManagerByEnterOperatorId.userId GROUP BY po.parkinfo.PId");

			Query queryObject = session.createQuery(sb.toString());
			List<ParkOrder> list = queryObject.list();
			return list;
		} catch (RuntimeException re) {
			re.getStackTrace();
			log.error("find all failed", re);
			throw re;
		}
	}

	public List getstatus() {
		log.debug("finding all ParkOrder instances");
		try {
			String queryString = "from ParkOrder group by status";
			Query queryObject = getSession().createQuery(queryString);
			return queryObject.list();
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}
	/*
	 *统计
	 *按天查询订单的数量
	 * 
	 */
	public String queryByDayo(List<StatusOrder> payInOut,List<ParkOrder> payStat,
			String daytime, Long userId) throws Exception {
		return this.queryByTimeo(payInOut,payStat,daytime, userId);
	}
	/*
	 *统计
	 *按周查询订单的数量
	 * 
	 */
	public Long[][] queryByWeeko(List<StatusOrder> payInOut,List<ParkOrder> payStat,
			Map<Double, Double> paylistInOutByDay, String weektime, Long userId)
					throws Exception {
		SimpleDateFormat formatDate = new SimpleDateFormat("yyyy-MM-dd");
		//String weektime = "2014-05-06";
		Date timelong = formatDate.parse(weektime);
		Timestamp inTime = new Timestamp(timelong.getTime());
		Timestamp outStartTime = new Timestamp(timelong.getTime());
		Timestamp outEndTime = new Timestamp(timelong.getTime());
		DateTimeTools.getWeekDays(inTime, outStartTime, outEndTime);//获取月的开始和结束时间，从而获取本月的最后一天，即获取本月的长度

		//查询 payInOut、payStat
		 	
		 
		session = this.getSession();
		
		//预定总量
		String hql ="select new com.bean.StatusOrder(count(*)) from ParkOrder" +
				" where createTime between ? and ? and poType=1";
		Query query = session.createQuery(hql);
		query.setTimestamp(0, outStartTime);
		query.setTimestamp(1, outEndTime);
		long count= 0;
		StatusOrder s=(StatusOrder) query.uniqueResult();
		if(s.getSumcount()!=0){
			s.setName("预定总量");
			count=s.getSumcount();
			s.setStatus((short) 0);
			payInOut.add(s);
		}
		//成交总量
		hql = "select new com.bean.StatusOrder(status,count(*)) from ParkOrder" +
				" where createTime between ? and ? and status=20 and poType=1";
				//" GROUP BY year(createTime),month(createTime) ";
		query = session.createQuery(hql);
		query.setTimestamp(0, outStartTime);
		query.setTimestamp(1, outEndTime);
		long count1= 0;
		StatusOrder s1=(StatusOrder) query.uniqueResult();
		
		if(s1.getSumcount()!=0){
			s1.setName("成交总量");
			count1=s1.getSumcount();
			s1.setStatus((short) 20);
			payInOut.add(s1);
		}
		//逃废总量
		hql = "select new com.bean.StatusOrder(status,count(*)) from ParkOrder" +
				" where createTime between ? and ? and status=5 and poType=1";
				//" GROUP BY year(createTime),month(createTime) ";
		query = session.createQuery(hql);
		query.setTimestamp(0, outStartTime);
		query.setTimestamp(1, outEndTime);
		long count2= 0;
		StatusOrder s2=(StatusOrder) query.uniqueResult();
		
		if(s2.getSumcount()!=0){
			s2.setName("逃费总量");
			count2=s2.getSumcount();
			s2.setStatus((short) 5);
			payInOut.add(s2);
		}
		//待支付总量
		hql = "select new com.bean.StatusOrder(status,count(*)) from ParkOrder" +
				" where createTime between ? and ? and status=4 and poType=1";
				//" GROUP BY year(createTime),month(createTime) ";
		query = session.createQuery(hql);
		query.setTimestamp(0, outStartTime);
		query.setTimestamp(1, outEndTime);
		long count3= 0;
		StatusOrder s3=(StatusOrder) query.uniqueResult();
		
		if(s3.getSumcount()!=0){
			s3.setName("待支付总量");
			count3=s3.getSumcount();
			s3.setStatus((short) 4);
			payInOut.add(s3);
		}
		//失败总量
		hql = "select new com.bean.StatusOrder(status,count(*)) from ParkOrder" +
				" where createTime between ? and ? and status in(-1,-2,-3,0) and poType=1";
				//" GROUP BY year(createTime),month(createTime) ";
		query = session.createQuery(hql);
		query.setTimestamp(0, outStartTime);
		query.setTimestamp(1, outEndTime);
		long count4= 0;
		StatusOrder s4=(StatusOrder) query.uniqueResult();
		if(s4.getSumcount()!=0){
			s4.setName("失败总量");
			count4=s4.getSumcount();
			s4.setStatus((short) 1);
			payInOut.add(s4);
		}

		//失败统计饼图
		hql = "select new com.bean.ParkOrder(status,count(*)) from ParkOrder"
				+ " where status in(-1,-2,-3,0) and poType=1 and createTime between ? and ? GROUP BY status";
		query = session.createQuery(hql);
		query.setTimestamp(0, outStartTime);
		query.setTimestamp(1, outEndTime);
		List<ParkOrder> p2 = query.list();
		payStat.addAll(p2);

		//统计7天数据
		//query paylistInOutByDay
		int enddate = 7;// outEndTime.getDate();
		Long[][] data = new Long[2][enddate];
		for(int i=0; i<2; i++){
			for(int j=0; j<enddate; j++){
				if(i==0)
					data[i][j] = (long)(j+1);
				else
					data[i][j] = (long) 0;
			}
		}
		hql = "select new com.bean.ParkOrder( year(createTime),MONTH(createTime),day(createTime),status,count(*)) from ParkOrder"
				+ " where status=20 and poType=1"
				+ " and createTime between ? and ? " 
				+ " GROUP BY year(createTime),MONTH(createTime),day(createTime),status";
		query = session.createQuery(hql);
		query.setTimestamp(0, outStartTime);
		query.setTimestamp(1, outEndTime);
		List<ParkOrder> list1 = query.list();
		if(list1!=null){
			for(ParkOrder par : list1){
				if(par!=null){
					int x = GetIndexByStatus(par.getStatus());
					int y = par.getDay() - outStartTime.getDate();
						data[x][y] = Math.abs(par.getCountOrder());
				}
			}
		}else{
			return null;
		}
		
		log.info( this.getClass()+".queryByWeek() "+data.toString());
		return data;
	}
	public List Year(String yeartime) throws Exception{
		session = this.getSession();
		String hql = "select new com.bean.ParkOrder(status,count(*)) from ParkOrder" +
				" where createTime like '"+yeartime+"%'  and status in(-1,-2,-3,0,4,5,20)  and poType=1"+
				" GROUP BY status,year(createTime),month(createTime) ";
		Query query = session.createQuery(hql);
		List<ParkOrder> list = query.list();
		return list;
	}
	/*
	 * 年
	 */
	public Long[][] queryByYearo(List<StatusOrder> payInOut,List<ParkOrder> payStat,
			Map<Double, Double> paylistInOutByDay, String yeartime, Long userId)
					throws Exception {
			session = this.getSession();
			
			//预定总量
			String hql ="select new com.bean.StatusOrder(count(*)) from ParkOrder" +
					" where createTime like '"+yeartime+"%' and poType=1";
			Query query = session.createQuery(hql);
			long count;
			StatusOrder s=(StatusOrder) query.uniqueResult();
			if(s.getSumcount()!=0){
				s.setName("预定总量");
				count=s.getSumcount();
				s.setStatus((short) 0);
				payInOut.add(s);
			}
			//成交总量
			hql = "select new com.bean.StatusOrder(status,count(*)) from ParkOrder" +
					" where status=20 and createTime like '"+yeartime+"%' and poType=1";
					//" GROUP BY year(createTime),month(createTime) ";
			query = session.createQuery(hql);
			long count1;
			StatusOrder s1=(StatusOrder) query.uniqueResult();
			if(s1.getSumcount()!=0){
				s1.setName("成交总量");
				count1=s1.getSumcount();
				s1.setStatus((short) 20);
				payInOut.add(s1);
			}
			
			//逃废总量
			hql = "select new com.bean.StatusOrder(status,count(*)) from ParkOrder" +
					" where createTime like '"+yeartime+"%'  and status=5 and poType=1";
					//" GROUP BY year(createTime),month(createTime) ";
			query = session.createQuery(hql);
			long count2;
			StatusOrder s2=(StatusOrder) query.uniqueResult();
			
			if(s2.getSumcount()!=0){
				s2.setName("逃费总量");
				count2=s2.getSumcount();
				s2.setStatus((short) 5);
				payInOut.add(s2);
			}
			//待支付总量
			hql = "select new com.bean.StatusOrder(status,count(*)) from ParkOrder" +
					" where createTime like '"+yeartime+"%'  and status=4 and poType=1";
					//" GROUP BY year(createTime),month(createTime) ";
			query = session.createQuery(hql);
			long count3;
			StatusOrder s3=(StatusOrder) query.uniqueResult();
			
			if(s3.getSumcount()!=0){
				s3.setName("待支付总量");
				count3=s3.getSumcount();
				s3.setStatus((short) 4);
				payInOut.add(s3);
			}
			//失败总量
			hql = "select new com.bean.StatusOrder(status,count(*)) from ParkOrder" +
					" where createTime like '"+yeartime+"%'  and status in(-1,-2,-3,0) and poType=1";
					//" GROUP BY year(createTime),month(createTime) ";
			query = session.createQuery(hql);
			long count4;
			StatusOrder s4=(StatusOrder) query.uniqueResult();
			if(s4.getSumcount()!=0){
				s4.setName("失败总量");
				count4=s4.getSumcount();
				s4.setStatus((short) 1);
				payInOut.add(s4);
			}
			
			//失败饼图
			hql = "select new com.bean.ParkOrder(status,count(*)) from ParkOrder" +
					" where createTime like '"+yeartime+"%'  and status in(-1,-2,-3,0) and poType=1"+
					" GROUP BY status";
			query = session.createQuery(hql);
			
			List<ParkOrder> list1 = query.list();
			if(list1!=null){
				payStat.addAll(list1);
			}
			
			int enddate = 12;// outEndTime.getDate();
			Long[][] data = new Long[2][enddate];
			for(int i=0; i<2; i++){
				for(int j=0; j<enddate; j++){
					if(i==0)
						data[i][j] = (long)(j+1);
					else
						data[i][j] = (long) 0;
				}
			}
			//折线图
			hql = "select new com.bean.ParkOrder(year(createTime),month(createTime),status,count(*)) from ParkOrder" +
					" where createTime like '"+yeartime+"%'  and status=20 and poType=1"+
					" GROUP BY year(createTime),MONTH(createTime)";
			query = session.createQuery(hql);
			List<ParkOrder> list2 = query.list();
			if(list2!=null){
				for(ParkOrder par : list2){
					if(par!=null){
						int x = GetIndexByStatus(par.getStatus());
						int y = par.getMonth() - 1;
							data[x][y] = Math.abs(par.getCountOrder());
					}
				}
			}else{
				return null;
			}
			log.info(this.getClass()+".queryByYear()"+  list2);
			return data;
	}
	/*
	 * 月
	 */
	public Long[][] queryByMontho(List<StatusOrder> payInOut,List<ParkOrder> payStat,
			Map<Double, Double> paylistInOutByDay, String monthtime, Long userId)
					throws Exception {
		{
			session = this.getSession();
			SimpleDateFormat formatDate = new SimpleDateFormat("yyyy-MM");
			//String datetime = "2014-05";
			Date timelong = formatDate.parse(monthtime);
			Timestamp inTime = new Timestamp(timelong.getTime());
			Timestamp outStartTime = new Timestamp(timelong.getTime());
			Timestamp outEndTime = new Timestamp(timelong.getTime());
			DateTimeTools.getMonthDays(inTime, outStartTime, outEndTime);//获取月的开始和结束时间，从而获取本月的最后一天，即获取本月的长度

			//预定总量
			String hql = "select new com.bean.StatusOrder(count(*)) from ParkOrder" +
					" where createTime like '"+monthtime+"%' and poType=1"+
					" GROUP BY year(createTime),month(createTime) ";
			Query query = session.createQuery(hql);
			long count= 0;
			StatusOrder s=(StatusOrder) query.uniqueResult();
			
			if(s!=null){
				s.setName("预定总量");
				count=s.getSumcount();
				s.setStatus((short) 0);
				payInOut.add(s);
			}
			
			//成交总量
			hql = "select new com.bean.StatusOrder(status,count(*)) from ParkOrder" +
					" where createTime like '"+monthtime+"%'  and status=20 and poType=1"+
					" GROUP BY year(createTime),month(createTime) ";
			query = session.createQuery(hql);
			long count1= 0;
			StatusOrder s1=(StatusOrder) query.uniqueResult();
			
			if(s1!=null){
				s1.setName("成交总量");
				count1=s1.getSumcount();
				s1.setStatus((short) 20);
				payInOut.add(s1);
			}
			//逃废总量
			hql = "select new com.bean.StatusOrder(status,count(*)) from ParkOrder" +
					" where createTime like '"+monthtime+"%'  and status=5 and poType=1"+
					" GROUP BY year(createTime),month(createTime) ";
			query = session.createQuery(hql);
			long count2= 0;
			StatusOrder s2=(StatusOrder) query.uniqueResult();
			
			if(s2!=null){
				s2.setName("逃费总量");
				count2=s2.getSumcount();
				s2.setStatus((short) 5);
				payInOut.add(s2);
			}
			//待支付总量
			hql = "select new com.bean.StatusOrder(status,count(*)) from ParkOrder" +
					" where createTime like '"+monthtime+"%'  and status=4 and poType=1"+
					" GROUP BY year(createTime),month(createTime) ";
			query = session.createQuery(hql);
			long count3= 0;
			StatusOrder s3=(StatusOrder) query.uniqueResult();
			
			if(s3!=null){
				s3.setName("待支付总量");
				count3=s3.getSumcount();
				s3.setStatus((short) 4);
				payInOut.add(s3);
			}
			//失败总量
			hql = "select new com.bean.StatusOrder(status,count(*)) from ParkOrder" +
					" where createTime like '"+monthtime+"%'  and status in(-1,-2,-3,0) and poType=1"+
					" GROUP BY year(createTime),month(createTime) ";
			query = session.createQuery(hql);
			long count4= 0;
			StatusOrder s4=(StatusOrder) query.uniqueResult();
			if(s4!=null){
				s4.setName("失败总量");
				count4=s4.getSumcount();
				s4.setStatus((short) 1);
				payInOut.add(s4);
			}
			
			//失败饼图
			hql = "select new com.bean.ParkOrder(status,count(*)) from ParkOrder" +
					" where createTime like '"+monthtime+"%'  and status in(-1,-2,-3,0) and poType=1"+
					" GROUP BY status,year(createTime),month(createTime) ";
			query = session.createQuery(hql);
			List<ParkOrder> list1 = query.list();
			if(list1!=null){
				payStat.addAll(list1);
			}
			//按day分类查询本月的折线图数据
			int enddate = outEndTime.getDate();
			Long[][] data1 = new Long[2][enddate];
			for(int i=0; i<2; i++){
				for(int j=0; j<enddate; j++){
					if(i==0)
						data1[i][j] = (long)(j+1);//日期，天
					else
						data1[i][j] = (long) 0;
				}
			}
			hql = "select new com.bean.ParkOrder(year(createTime),MONTH(createTime),day(createTime),status,count(*)) from ParkOrder" +
					" where createTime like '"+monthtime+"%' and poType=1 and status=20"+
					" GROUP BY year(createTime),MONTH(createTime),day(createTime),status";
			query = session.createQuery(hql);
			List<ParkOrder> list2 = query.list();
			if(list2!=null){
				for(ParkOrder par : list2){
					int x = GetIndexByStatus(par.getStatus());
					int y= par.getDay()-1;
						data1[x][y] = Math.abs(par.getCountOrder());
				}
			}else{
				return null;
			}
			log.info( data1.toString());
			return data1;
		}
	}
	
	/*
	 * 时间
	 */
	public String queryByTimeo(List<StatusOrder> payInOut,List<ParkOrder> payStat,
			String daytime, Long userId)
			throws Exception {

		session = this.getSession();
		//预定总量
		String hql = "select new com.bean.StatusOrder(count(*)) from ParkOrder" +
				" where createTime like '"+daytime+"%' and poType=1"+
				" GROUP BY year(createTime),month(createTime) ";
		Query query = session.createQuery(hql);
		long count;
		StatusOrder s=(StatusOrder) query.uniqueResult();
		if(s!=null){
			s.setName("预定总量");
			count=s.getSumcount();
			s.setStatus((short) 0);
			payInOut.add(s);
		}
		
		//成交总量
		hql = "select new com.bean.StatusOrder(status,count(*)) from ParkOrder" +
				" where createTime like '"+daytime+"%'  and status=20 and poType=1";
				//" GROUP BY year(createTime),month(createTime) ";
		query = session.createQuery(hql);
		long count1;
		StatusOrder s1=(StatusOrder) query.uniqueResult();
		
		if(s1.getSumcount()!=0){
			s1.setName("成交总量");
			count1=s1.getSumcount();
			s1.setStatus((short) 20);
			payInOut.add(s1);
		}
		//逃废总量
		hql = "select new com.bean.StatusOrder(status,count(*)) from ParkOrder" +
				" where createTime like '"+daytime+"%'  and status=5 and poType=1";
				//" GROUP BY year(createTime),month(createTime) ";
		query = session.createQuery(hql);
		long count2;
		StatusOrder s2=(StatusOrder) query.uniqueResult();
		
		if(s2.getSumcount()!=0){
			s2.setName("逃费总量");
			count2=s2.getSumcount();
			s2.setStatus((short) 5);
			payInOut.add(s2);
		}
		//待支付总量
		hql = "select new com.bean.StatusOrder(status,count(*)) from ParkOrder" +
				" where createTime like '"+daytime+"%'  and status=4 and poType=1";
				//" GROUP BY year(createTime),month(createTime) ";
		query = session.createQuery(hql);
		long count3;
		StatusOrder s3=(StatusOrder) query.uniqueResult();
		
		if(s3.getSumcount()!=0){
			s3.setName("待支付总量");
			count3=s3.getSumcount();
			s3.setStatus((short) 4);
			payInOut.add(s3);
		}
		//失败总量
		hql = "select new com.bean.StatusOrder(status,count(*)) from ParkOrder" +
				" where createTime like '"+daytime+"%'  and status in(-1,-2,-3,0) and poType=1";
				//" GROUP BY year(createTime),month(createTime) ";
		query = session.createQuery(hql);
		long count4;
		StatusOrder s4=(StatusOrder) query.uniqueResult();
		if(s4.getSumcount()!=0){
			s4.setName("失败总量");
			count4=s4.getSumcount();
			s4.setStatus((short) 1);
			payInOut.add(s4);
		}
		
		//失败饼图
		hql = "select new com.bean.ParkOrder( status,count(*)) from ParkOrder"
				+ " where status in(-1,-2,-3,0) and poType=1"
				+ " and createTime like '"
				+ daytime + "%' group by status";
		query = session.createQuery(hql);
		List<ParkOrder> p2 = query.list();
		if(p2!=null)
			payStat.addAll(p2);
		
		log.info("payInOut.size=" + payInOut.size());
		log.info("payStat.size=" + payStat.size());
		return GUtil.SUCCESS;
	}
	public List<ParkOrder> getOrderList(Long id) {
		log.debug("finding all ParkOrder instances");
		try {
			String queryString = "from ParkOrder where reservation_operator_id=?";
			Query queryObject = getSession().createQuery(queryString);
			queryObject.setLong(0, id);
			return queryObject.list();
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}

	
	public int GetIndexByStatus(int status){
		switch(status){
		case -1:
			return -1;
		case -2:
			return -2;
		case -3:
			return -3;
		case 0:
			return 0;
		case 4:
			return 4;
		case 5:
			return 5;
		case 20:
			return 1;
		}
		return -100;
	}
	
	
	/*
	 * 车场查询金额
	 */
//	public Long[][] queryByparkinfo(List<Money> moneyList,Map<Double, Double> paylistInOutByDay, Short pid, Long userId)throws Exception{
//		session = this.getSession();
//		//实际交易总额所占百分比。/////////////////////////////////////////////////////
//		//按day分类查询本月的折线图数据
//		int enddate = outEndTime.getDate();
//		Long[][] data1 = new Long[5][enddate];
//		for(int i=0; i<5; i++){
//			for(int j=0; j<enddate; j++){
//				if(i==0)
//					data1[i][j] = (long)(j+1);//日期，天
//				else
//					data1[i][j] = (long) 0;
//			}
//		}
//		//实际交易额
//		String hql="SELECT new com.bean.Money(SUM(actualAmount), status) from ParkOrder where status=20 and parkinfo.PId in(SELECT PId from ParkinfoManagerRelevance WHERE userId=?) and parkinfo.PId = '"+pid+"'";
//		Query query=session.createQuery(hql);
//		query.setLong(0, userId);
//		double sum1=0;
//		Money m1 = (Money)query.uniqueResult();
//		if(m1!=null){
//			m1.setName("实际交易总额");
//			sum1 = m1.getSummoney();
//			m1.setStatus((short) 20);
//			moneyList.add(m1);
//		}
//
//		//逃废
//		hql="SELECT new com.bean.Money(SUM(actualAmount), status) from ParkOrder where status=5 and parkinfo.PId in(SELECT PId from ParkinfoManagerRelevance WHERE userId=?) and parkinfo.PId = '"+pid+"'";
//		query=session.createQuery(hql);
//		query.setLong(0, userId);
//		Money m2=(Money) query.uniqueResult();
//		double sum2=0;
//		if(m2!=null){
//			sum2 = m2.getSummoney();
//			m2.setStatus((short) 5);
//			m2.setName("逃费");
//			moneyList.add(m2);
//		}
//		
//		//欠费
//		hql="SELECT new com.bean.Money(SUM(actualAmount), status) from ParkOrder where status=4 and parkinfo.PId in(SELECT PId from ParkinfoManagerRelevance WHERE userId=?) and parkinfo.PId = '"+pid+"'";
//		query=session.createQuery(hql);
//		query.setLong(0, userId);
//		Money m3=(Money) query.uniqueResult();
//		double sum3 = 0;
//		if(m3!=null){
//			m3.setName("欠费");
//			m3.setStatus((short) 4);
//			sum3 = m3.getSummoney();
//			moneyList.add(m3);
//		}
//		//应收总额
//		
//		hql="SELECT new com.bean.Money(SUM(actualAmount), status) from ParkOrder where status in(4,5,20) and parkinfo.PId in(SELECT PId from ParkinfoManagerRelevance WHERE userId=?)and parkinfo.PId = '"+pid+"'";
//		query=session.createQuery(hql);
//		query.setLong(0, userId);
//		Money m4=(Money) query.uniqueResult();
//		if(m4!=null){
//			//差额
//			double sum = m4.getSummoney();
//			double chae = sum - sum1 - sum2 - sum3;
//			Money m5 = new Money(chae, 21);
//			m4.setName("应收费金额");
//			m4.setStatus((short) 0);
//			m5.setName("差额");
//			moneyList.add(m5);
//			moneyList.add(m4);
//		}
//		
//		log.info(this.getClass()+".queryByYear()"+  moneyList);
//		
//		return data;
//	}
	
	/*
	 *统计
	 *按天查询订单的数量
	 * 
	 */
	public String queryByDay(List<ParkOrder> payInOut, List<Money> moneyList,
			String daytime, Long userId) throws Exception {
		return this.queryByTime(payInOut, moneyList, daytime, userId);
	}
	/*
	 *统计
	 *按周查询订单的数量
	 * 
	 */
	public Long[][] queryByWeek(List<ParkOrder> payInOut,
			List<Money> moneyList,
			Map<Double, Double> paylistInOutByDay, String weektime, Long userId)
					throws Exception {

		SimpleDateFormat formatDate = new SimpleDateFormat("yyyy-MM-dd");
		//String weektime = "2014-05-06";
		Date timelong = formatDate.parse(weektime);
		Timestamp inTime = new Timestamp(timelong.getTime());
		Timestamp outStartTime = new Timestamp(timelong.getTime());
		Timestamp outEndTime = new Timestamp(timelong.getTime());
		DateTimeTools.getWeekDays(inTime, outStartTime, outEndTime);//获取月的开始和结束时间，从而获取本月的最后一天，即获取本月的长度

		//查询 payInOut、payStat
		 	
		 
		session = this.getSession();
		String hql = "select new com.bean.ParkOrder( status,count(*)) from ParkOrder"
				+ " where parkinfo.PId in(SELECT PId from ParkinfoManagerRelevance where userId=? ) and status in(-1,4,5,20)"
				+ " and leaveTime between ? and ? GROUP BY status";
		Query query = session.createQuery(hql);
		query.setLong(0, userId);
		query.setTimestamp(1, outStartTime);
		query.setTimestamp(2, outEndTime);
		List<ParkOrder> p1 = query.list();
		payInOut.addAll(p1);

		//实际交易总额所占百分比。/////////////////////////////////////////////////////
				//实际交易额
				hql="SELECT new com.bean.Money(SUM(actualAmount), status) from ParkOrder where status=20 and parkinfo.PId in(SELECT PId from ParkinfoManagerRelevance WHERE userId=?) and leaveTime  between ? and ?";
				query=session.createQuery(hql);
				query.setLong(0, userId);
				query.setTimestamp(1, outStartTime);
				query.setTimestamp(2, outEndTime);
				Money m1 = (Money) query.uniqueResult();
				double sum1 = 0;
				if(m1!=null){
					m1.setName("实际交易总额");
					sum1 = m1.getSummoney();
					m1.setStatus((short) 20);
					moneyList.add(m1);
				}
				
				//逃费
				hql="SELECT new com.bean.Money(SUM(receivableAmount), status) from ParkOrder where status=5 and parkinfo.PId in(SELECT PId from ParkinfoManagerRelevance WHERE userId=?) and leaveTime  between ? and ?";
				query=session.createQuery(hql);
				query.setLong(0, userId);
				query.setTimestamp(1, outStartTime);
				query.setTimestamp(2, outEndTime);
				Money m2=(Money) query.uniqueResult();
				double sum2 = 0;
				if(m2!=null){
					sum2 = m2.getSummoney();
					m2.setStatus((short) 5);
					m2.setName("逃费");
					moneyList.add(m2);
				}
				
				//欠费
				hql="SELECT new com.bean.Money(SUM(receivableAmount), status) from ParkOrder where status=4 and parkinfo.PId in(SELECT PId from ParkinfoManagerRelevance WHERE userId=?) and leaveTime  between ? and ?";
				query=session.createQuery(hql);
				query.setLong(0, userId);
				query.setTimestamp(1, outStartTime);
				query.setTimestamp(2, outEndTime);
				Money m3=(Money) query.uniqueResult();
				double sum3 = 0;
				if(m3!=null){
					m3.setName("欠费");
					sum3 = m3.getSummoney();
					m3.setStatus((short) 4);
					moneyList.add(m3);
				}
				
				//应收总额
				hql="SELECT new com.bean.Money(SUM(receivableAmount), status) from ParkOrder where status in(4,5,20) and parkinfo.PId in(SELECT PId from ParkinfoManagerRelevance WHERE userId=?) and leaveTime  between ? and ?";
				query=session.createQuery(hql);
				query.setLong(0, userId);
				query.setTimestamp(1, outStartTime);
				query.setTimestamp(2, outEndTime);
				Money m4 = (Money) query.uniqueResult();
				if(m4!=null){
					//差额
					double sum = m4.getSummoney();
					double chae = sum - sum1 - sum2 - sum3;
					m4.setName("应收费金额");
					Money m5 = new Money(chae, 21);
					m4.setStatus((short) 0);
					m5.setName("差额");
					moneyList.add(m4);
					moneyList.add(m5);
				}
				
				//////////////////////////////end///////////////////////////
				 

		//统计7天数据
		//query paylistInOutByDay
		int enddate = 7;// outEndTime.getDate();
		Long[][] data = new Long[5][enddate];
		for(int i=0; i<5; i++){
			for(int j=0; j<enddate; j++){
				if(i==0)
					data[i][j] = (long)(j+1);
				else
					data[i][j] = (long) 0;
			}
		}
		hql = "select new com.bean.ParkOrder( year(leaveTime),MONTH(leaveTime),day(leaveTime),status,count(*)) from ParkOrder"
				+ " where parkinfo.PId in(SELECT PId from ParkinfoManagerRelevance where userId=? ) and status in(-1,4,5,20)"
				+ " and leaveTime between ? and ? " 
				+ " GROUP BY day(leaveTime),status ";
		query = session.createQuery(hql);
		query.setLong(0, userId);
		query.setTimestamp(1, outStartTime);
		query.setTimestamp(2, outEndTime);
		List<ParkOrder> list1 = query.list();
		if(list1!=null){
			for(ParkOrder par : list1){
				if(par!=null){
					int x = GetIndexByStatus(par.getStatus());
					int y = par.getDay() - outStartTime.getDate();
					if(x>0 && x < 5)
						data[x][y] = Math.abs(par.getCountOrder());
				}
			}
		}else{
			return null;
		}
		
		log.info( this.getClass()+".queryByWeek() "+data.toString());
		return data;
	}
	/*
	 * 年
	 */
	public Double [][] queryByYear(List<ParkOrder> payInOut,
			List<Money> moneyList,
			Map<Double, Double> paylistInOutByDay, String yeartime, Long userId)
					throws Exception {
		
			int enddate = 12;// outEndTime.getDate();
			Double[][] data = new Double[4][enddate];
			for(int i=0; i<4; i++){
				for(int j=0; j<enddate; j++){
					if(i==0)
						data[i][j] = (double)(j+1);
					else
						data[i][j] = 0.0;
				}
			}
			
			session = this.getSession();
			String hql = "select new com.bean.ParkOrder(status,count(*)) from ParkOrder" +
					" where parkinfo.PId in(SELECT PId from ParkinfoManagerRelevance where userId=? ) and leaveTime like '"+yeartime+"%'  and status in(-1,4,5,20) "+
					" GROUP BY status,year(leaveTime),month(leaveTime) ";
			Query query = session.createQuery(hql);
			query.setLong(0, userId);
			
			List<ParkOrder> list = query.list();
			if(list!=null){
				payInOut.addAll(list);
			}
			
			//实际交易总额所占百分比。/////////////////////////////////////////////////////
			//实际交易额
			hql="SELECT new com.bean.Money(SUM(actualAmount), status) from ParkOrder where status=20 and parkinfo.PId in(SELECT PId from ParkinfoManagerRelevance WHERE userId=?) and leaveTime  like '"+yeartime+"%'";
			query=session.createQuery(hql);
			query.setLong(0, userId);
			double sum1=0;
			Money m1 = (Money)query.uniqueResult();
			if(m1!=null){
				m1.setName("实际交易总额");
				sum1 = m1.getSummoney();
				m1.setStatus((short) 20);
				moneyList.add(m1);
			}
			
			
			//逃废
			hql="SELECT new com.bean.Money(SUM(actualAmount), status) from ParkOrder where status=5 and parkinfo.PId in(SELECT PId from ParkinfoManagerRelevance WHERE userId=?) and leaveTime  like '"+yeartime+"%'";
			query=session.createQuery(hql);
			query.setLong(0, userId);
			Money m2=(Money) query.uniqueResult();
			double sum2=0;
			if(m2!=null){
				sum2 = m2.getSummoney();
				m2.setStatus((short) 5);
				m2.setName("逃费");
				moneyList.add(m2);
			}
			
			//欠费
			hql="SELECT new com.bean.Money(SUM(actualAmount), status) from ParkOrder where status=4 and parkinfo.PId in(SELECT PId from ParkinfoManagerRelevance WHERE userId=?) and leaveTime  like '"+yeartime+"%'";
			query=session.createQuery(hql);
			query.setLong(0, userId);
			Money m3=(Money) query.uniqueResult();
			double sum3 = 0;
			if(m3!=null){
				m3.setName("欠费");
				m3.setStatus((short) 4);
				sum3 = m3.getSummoney();
				moneyList.add(m3);
			}
			//应收总额
			
			hql="SELECT new com.bean.Money(SUM(actualAmount), status) from ParkOrder where status in(4,5,20) and parkinfo.PId in(SELECT PId from ParkinfoManagerRelevance WHERE userId=?) and leaveTime  like '"+yeartime+"%'";
			query=session.createQuery(hql);
			query.setLong(0, userId);
			Money m4=(Money) query.uniqueResult();
			if(m4!=null){
				//差额
				double sum = m4.getSummoney();
				double chae = sum - sum1 - sum2 - sum3;
				Money m5 = new Money(chae, 21);
				m4.setName("应收费金额");
				m4.setStatus((short) 0);
				m5.setName("差额");
				moneyList.add(m5);
				moneyList.add(m4);
			}
			
			log.info(this.getClass()+".queryByYear()"+  list);
			return data;
	}
	/*
	 * 月
	 */
	public Long[][] queryByMonth(List<ParkOrder> payInOut,
			List<Money> moneyList,
			Map<Double, Double> paylistInOutByDay, String monthtime, Long userId)
					throws Exception {
		{
			session = this.getSession();
			SimpleDateFormat formatDate = new SimpleDateFormat("yyyy-MM");
			//String datetime = "2014-05";
			Date timelong = formatDate.parse(monthtime);
			Timestamp inTime = new Timestamp(timelong.getTime());
			Timestamp outStartTime = new Timestamp(timelong.getTime());
			Timestamp outEndTime = new Timestamp(timelong.getTime());
			DateTimeTools.getMonthDays(inTime, outStartTime, outEndTime);//获取月的开始和结束时间，从而获取本月的最后一天，即获取本月的长度
			
			//按status分类查询饼图数据
			String hql = "select new com.bean.ParkOrder(year(leaveTime),MONTH(leaveTime),day(leaveTime),status,count(*)) from ParkOrder" +
					" where parkinfo.PId in(SELECT PId from ParkinfoManagerRelevance where userId=? ) and leaveTime like '"+monthtime+"%'  and status in(-1,4,5,20) "+
					" GROUP BY status,year(leaveTime),month(leaveTime) ";
			Query query = session.createQuery(hql);
			query.setLong(0, userId);
			List<ParkOrder> list = query.list();
			if(list!=null){
				payInOut.addAll(list);
			}
			
			//实际交易总额所占百分比。/////////////////////////////////////////////////////
			
			//应收总额
			hql="SELECT new com.bean.Money(SUM(actualAmount), status) from ParkOrder where status in(4,5,20) and parkinfo.PId in(SELECT PId from ParkinfoManagerRelevance WHERE userId=?) and leaveTime  like '"+monthtime+"%'";
			query=session.createQuery(hql);
			query.setLong(0, userId);
			Money m4=(Money) query.uniqueResult();
			double sum = 0;
			if(m4!=null){
				//差额
				m4.setName("应收费金额");
				sum = m4.getSummoney();
				m4.setStatus((short) 0);
				moneyList.add(m4);
			}
			
			//实际交易额
			hql="SELECT new com.bean.Money(SUM(actualAmount), status) from ParkOrder where status=20 and parkinfo.PId in(SELECT PId from ParkinfoManagerRelevance WHERE userId=?) and leaveTime  like '"+monthtime+"%'";
			query=session.createQuery(hql);
			query.setLong(0, userId);
			double sum1=0;
			Money m1 = (Money)query.uniqueResult();
			if(m1!=null){
				m1.setName("实际交易总额");
				sum1 = m1.getSummoney();
				m1.setStatus((short)20);
				moneyList.add(m1);
			}
			
			
			//逃废
			hql="SELECT new com.bean.Money(SUM(actualAmount), status) from ParkOrder where status=5 and parkinfo.PId in(SELECT PId from ParkinfoManagerRelevance WHERE userId=?) and leaveTime  like '"+monthtime+"%'";
			query=session.createQuery(hql);
			query.setLong(0, userId);
			Money m2=(Money) query.uniqueResult();
			double sum2=0;
			if(m2!=null){
				sum2 = m2.getSummoney();
				m2.setName("逃费");
				m2.setStatus((short)5);
				moneyList.add(m2);
			}
			
			//欠费
			hql="SELECT new com.bean.Money(SUM(actualAmount), status) from ParkOrder where status=4 and parkinfo.PId in(SELECT PId from ParkinfoManagerRelevance WHERE userId=?) and leaveTime  like '"+monthtime+"%'";
			query=session.createQuery(hql);
			query.setLong(0, userId);
			Money m3=(Money) query.uniqueResult();
			double sum3 = 0;
			if(m3!=null){
				m3.setName("欠费");
				sum3 = m3.getSummoney();
				m3.setStatus((short)4);
				moneyList.add(m3);
			}
		
			
			double chae = sum - sum1 - sum2 - sum3;
			Money m5 = new Money(chae, 21);
			m5.setName("差额");
			moneyList.add(m5);
			
			//////////////////////////////end///////////////////////////
			
			
			//按day分类查询本月的折线图数据
			int enddate = outEndTime.getDate();
			Long[][] data1 = new Long[5][enddate];
			for(int i=0; i<5; i++){
				for(int j=0; j<enddate; j++){
					if(i==0)
						data1[i][j] = (long)(j+1);//日期，天
					else
						data1[i][j] = (long) 0;
				}
			}
			hql = "select new com.bean.ParkOrder(year(leaveTime),MONTH(leaveTime),day(leaveTime),status,count(*)) from ParkOrder" +
					" where parkinfo.PId in(SELECT PId from ParkinfoManagerRelevance where userId=? ) " +
					" and leave_time like '"+monthtime+"%'  and status in(-1,4,5,20) "+
					" GROUP BY day(leaveTime),status ";
			query = session.createQuery(hql);
			query.setLong(0, userId);
			List<ParkOrder> list2 = query.list();
			
			if(list2!=null){
				for(ParkOrder par : list2){
					int index = GetIndexByStatus(par.getStatus());
					if(index>0 && index < 5)
						data1[index][par.getDay()-1] = Math.abs(par.getCountOrder());
				}
			}else{
				return null;
			}
			log.info( data1.toString());
			return data1;
		}
	}
	/*
	 * 时间
	 */
	public String queryByTime(List<ParkOrder> payInOut,
			List<Money> moneyList, String daytime, Long userId)
			throws Exception {

		session = this.getSession();
		String hql = "select new com.bean.ParkOrder( status,count(*)) from ParkOrder"
				+ " where parkinfo.PId in(SELECT PId from ParkinfoManagerRelevance where userId=? ) and status in(-1,4,5,20)"
				+ " and leaveTime like '"
				+ daytime + "%'" + " GROUP BY status";
		Query query = session.createQuery(hql);
		query.setLong(0, userId);
		List<ParkOrder> p1 = query.list();
		payInOut.addAll(p1);
		
		
		//实际交易总额所占百分比。/////////////////////////////////////////////////////
		//实际交易额
		hql="SELECT new com.bean.Money(SUM(actualAmount), status) from ParkOrder where status=20 and parkinfo.PId in(SELECT PId from ParkinfoManagerRelevance WHERE userId=?) and leaveTime  like '"+daytime+"%'";
		query=session.createQuery(hql);
		query.setLong(0, userId);
		double sum1=0;
		Money m1 = (Money)query.uniqueResult();
		if(m1!=null){
			m1.setName("实际交易总额");
			sum1 = m1.getSummoney();
			m1.setStatus((short)20);
			moneyList.add(m1);
		}
		
		
		//逃废
		hql="SELECT new com.bean.Money(SUM(actualAmount), status) from ParkOrder where status=5 and parkinfo.PId in(SELECT PId from ParkinfoManagerRelevance WHERE userId=?) and leaveTime  like '"+daytime+"%'";
		query=session.createQuery(hql);
		query.setLong(0, userId);
		Money m2=(Money) query.uniqueResult();
		double sum2=0;
		if(m2!=null){
			sum2 = m2.getSummoney();
			m2.setName("逃费");
			m2.setStatus((short)5);
			moneyList.add(m2);
		}
		
		//欠费
		hql="SELECT new com.bean.Money(SUM(actualAmount), status) from ParkOrder where status=4 and parkinfo.PId in(SELECT PId from ParkinfoManagerRelevance WHERE userId=?) and leaveTime  like '"+daytime+"%'";
		query=session.createQuery(hql);
		query.setLong(0, userId);
		Money m3=(Money) query.uniqueResult();
		double sum3 = 0;
		if(m3!=null){
			m3.setName("欠费");
			m3.setStatus((short)4);
			sum3 = m3.getSummoney();
			moneyList.add(m3);
		}
		//应收总额
		
		hql="SELECT new com.bean.Money(SUM(actualAmount), status) from ParkOrder where status in(4,5,20) and parkinfo.PId in(SELECT PId from ParkinfoManagerRelevance WHERE userId=?) and leaveTime  like '"+daytime+"%'";
		query=session.createQuery(hql);
		query.setLong(0, userId);
		Money m4=(Money) query.uniqueResult();
		if(m4!=null){
			//差额
			double sum = m4.getSummoney();
			m4.setStatus((short)0);
			double chae = sum - sum1 - sum2 - sum3;
			Money m5 = new Money(chae, 21);
			m4.setName("应收费金额");
			m5.setName("差额");
			moneyList.add(m4);
			moneyList.add(m5);
		}
		//////////////////////////////end///////////////////////////
		log.info("payInOut.size=" + payInOut.size());
		log.info("payStat.size=" + moneyList.size());

		return GUtil.SUCCESS;
	}
	
}